/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pstchart.hpp - Definition for the PegStripChart object
//
// Author: Jim DeLisle
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PSTCHART_HPP_
#define _PSTCHART_HPP_

// Forward reference
class PegStripChart;

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegStripChartLine
{
    public:
        PegStripChartLine(PegStripChart* pParent, PEGUBYTE Id, 
                          PEGCOLOR Color, PEGCOLOR AgedColor, 
                          PEGCOLOR FillColor = 0, PEGCOLOR LeaderColor = 0); 
        virtual ~PegStripChartLine();
    
        PEGBOOL AddData(PEGLONG Data);
    
        // Accessors
        PEGCOLOR GetAgedColor() const { return mAgedColor; }
        PEGCOLOR GetColor() const { return mColor; }
        PEGLONG* GetData() const { return mpData; }
        PEGLONG GetData(PEGUINT index) { return mpData[index]; }
        PEGCOLOR GetFillColor() const { return mFillColor; }
        PEGUBYTE GetID() const { return mID; }
        PEGUINT GetHead() const { return mHead; }
        PEGCOLOR GetLeaderColor() const { return mLeaderColor; }
        PegStripChartLine* GetNext() const { return mpNext; }
        PEGUINT GetTail() const { return mTail; }
        PEGUINT GetViewHead() const { return mViewHead; }
        PEGUINT GetViewTail() const { return mViewTail; }
        PEGBOOL ScrollFilled() const { return mScrollFilled; }
    
        // Mutators
        PEGCOLOR SetAgedColor(PEGCOLOR Color) 
        {
            mAgedColor = Color;
            return mAgedColor; 
        }
        PEGCOLOR SetColor(PEGCOLOR Color)
        {
            mColor = Color;
            return mColor;
        }
        PEGCOLOR SetFillColor(PEGCOLOR Color)
        {
            mFillColor = Color;
            return mFillColor;
        }
        PEGCOLOR SetLeaderColor(PEGCOLOR Color)
        {
            mLeaderColor = Color;
            return mLeaderColor;
        }
        void SetNext(PegStripChartLine* pLine) { mpNext = pLine; }
        void SetScrollFilled(PEGBOOL Filled) { mScrollFilled = Filled; }
        
    protected:
        PegStripChartLine* mpNext;
        PegStripChart* mpParent;
        PEGLONG*       mpData;
        PEGUINT        mHead;
        PEGUINT        mTail;
        PEGUINT        mViewHead;
        PEGUINT        mViewTail;
        PEGUINT        mRecordLength;
        PEGCOLOR       mColor;
        PEGCOLOR       mAgedColor;
        PEGCOLOR       mFillColor;
        PEGCOLOR       mLeaderColor;
        PEGBOOL        mScrollFilled;
        PEGUBYTE       mID;
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegStripChart : public PegChart
{
    public:
        PegStripChart(const PegRect &Size, PEGUINT Samples, PEGLONG MinY,
                      PEGLONG MaxY, PEGUINT XScale = 0, PEGUINT YScale = 0);
        virtual ~PegStripChart();
    
        // Add new data to a line
        PEGBOOL AddData(PEGUBYTE ID, PEGLONG rawData, PEGBOOL Redraw = TRUE);

        // returns the indice of the new line
        PEGUBYTE AddLine(PEGCOLOR Color, PEGCOLOR AgedColor, 
                         PEGCOLOR FillColor = 0);

        virtual void Draw(const PegRect &Invalid);

        // Line wrappers
        PEGCOLOR GetLineAgedColor(PEGUBYTE ID);
        PEGCOLOR GetLineColor(PEGUBYTE ID);
        PEGCOLOR GetLineFillColor(PEGUBYTE ID);
        PEGCOLOR GetLineLeaderColor(PEGUBYTE ID);

        PEGINT IndexToPointX(PEGUINT Index);
        virtual PEGINT Message(const PegMessage& Mesg);
        virtual void RecalcSize(const PegRect& NewSize, PEGBOOL Redraw = TRUE);

        // returns success/failure
        PEGBOOL RemoveLine(PEGUBYTE ID);
        virtual void Resize(const PegRect &Size);

        void SetLineAgedColor(PEGUBYTE ID, PEGCOLOR Color);
        void SetLineColor(PEGUBYTE ID, PEGCOLOR Color);
        void SetLineFillColor(PEGUBYTE ID, PEGCOLOR Color);
        void SetLineLeaderColor(PEGUBYTE ID, PEGCOLOR Color);

        // Convert raw data to screen point values
        PEGINT ValToPointY(PEGLONG Val);

    protected:
        // Line drawing methods
        virtual void DrawInvalidChartRegion(const PegRect &Invalid);
        virtual void DrawLine(const PegRect &Invalid, PegStripChartLine* pLine);
        virtual void DrawLineHistory(const PegRect &Invalid, 
                                     PegStripChartLine* pLine);
        virtual void DrawNewLineData(PegStripChartLine* pLine);
    
        PegStripChartLine* GetLineByID(PEGUBYTE ID);
    
        PegStripChartLine* mpLines;
        PEGULONG mLineIDs[8];
};

#endif // _PSTCHART_HPP_


